<template>
	<view>
		<custom-header title="平台公告" />
		<scroll-view
			:scroll-y="true" 
			scroll-with-animation
			:style="{height:'calc(100vh - 5rpx - '+statusBarHeight+'px)'}"
			class="scroll_content_wrap">
				<view class="_wrap">
					<view class="header">
						<view class="title">{{detail.title}}</view>
						<view class="source_wrap">
							<view class="tx">
								<image :src="detail.coverId || 'https://goods-1312936761.cos.ap-chongqing.myqcloud.com/applet/supplier/my/service_tx.png'" mode=""></image>
							</view>
							<view class="info">
								<view class="name">亚拍鲜花官方</view>
								<view class="time_count">
									<view class="time">
										{{detail.createTime}}
									</view>
									<view class="count">
										<view class="icon">
											<image src="/static/common/eye.png" mode=""></image>
										</view>
										<view class="text">{{detail.viewNum}}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="content_wrap">
						{{detail.content}}
					</view>
				</view>
		</scroll-view>
	</view>
</template>

<script setup>
	import { computed, ref } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import { useStore } from 'vuex';
	import noticeApi from '@/api/notice'

	const store = useStore()

	const statusBarHeight = computed(()=>{
		return store.getters.statusBarHeight
	})

	// 公告详情数据
	const detail = ref({})
	const noticeId = ref('')

	const getNoticeDetail = async () => {
		if (!noticeId.value) {
			console.error('缺少公告ID参数')
			uni.showToast({
				title: '参数错误，请重试',
				icon: 'none'
			})
			setTimeout(() => {
				uni.navigateBack()
			}, 1500)
			return
		}

		try {
			const response = await noticeApi.getDetail(noticeId.value);
			detail.value = response;
		} catch (error) {
			console.error('获取公告详情失败:', error);
			uni.showToast({
				title: '获取公告详情失败',
				icon: 'none'
			})
		}
	}

	onLoad((options) => {
		if (options.id) {
			noticeId.value = options.id
			getNoticeDetail()
		} else {
			console.error('缺少公告ID参数')
			uni.showToast({
				title: '参数错误',
				icon: 'none'
			})
			setTimeout(() => {
				uni.navigateBack()
			}, 1500)
		}
	})
</script>

<style lang="scss">
	._wrap{
		padding: 20rpx;
	}
	.title{
		font-size: 36rpx;
		color: #333;
		font-weight: bold;
	}
	.header{
		padding: 0 20rpx;
	}
	.source_wrap{
		display: flex;
		padding: 30rpx 0;
		.tx{
			width: 88rpx;
			height: 88rpx;
		}
		.info{
			padding-left: 20rpx;
			.name{
				font-size: 28rpx;
				color: #333;
			}
			.time_count{
				font-size: 24rpx;
				color: #999;
				display: flex;
				padding-top: 15rpx;
				.count{
					padding-left: 40rpx;
					display: flex;
					align-items: center;
					.icon{
						width: 24rpx;
						height: 18rpx;
						display: flex;
					}
					.text{
						padding-left: 10rpx;
					}
				}
				
			}
		}
	}
</style>
